/**
 * 
 */
var xmlHttp=null ;
var g_basisObj = null; 	//包括用户信息及navbar信息等
                        //当是游客信息时，其user变量为空字符串
var g_appObj = null;	//每个具体模块的全局对象

/*形如：
 * "{"
+"   'user':'dqjbd',"
+"   'id':'role0',"
+"   'topic':["
+"       {"
+"          'name':'基本信息',"  	//topic[0].name
+"          'item':["			//topic[0].item[0].name
+"              {'name':'完善个人信息','value':'peinfo'},"
+"              {'name':'密码修改','value':'repwd'}      "
+"           ]"
+"        },"
+"       {"
+"          'name':'基本功能',"
+"          'item':["
+"              {'name':'报告上传','value':'reportsubmit'},"
+"              {'name':'进行考试','value':'examsubmit'}      "
+"           ]"
+"        },"
+"    ]"
+"}"

 * 
 */
function init(){
	//初始化ajax通信变量
	xmlHttp = g_createHttpRQ();
	//进行菜单消息注册
	g_addNameEvent("startfind","click",startFind);
	g_addNameEvent("IntervalQuery","click",IntervalQuery);
	g_addNameEvent("WiseQuery","click",WiseQuery);
}

//------始发查询代码-------

function startFind(e){
	var obj = e.target || window.event.srcElement;
	switch(obj.getAttribute("key")){
	case "train":
		g_appObj = new TrainStartFind();
		break;	
	case "air":
		g_appObj = new AirStartFind();
		break;
	case "bus":
		g_appObj = new BusStartFind();
		break;
	}
	g_appObj.loadEngine();	
}

//-------TrainStartFind代码--------

function TrainStartFind(){
	
}

TrainStartFind.prototype.loadEngine = function(){
	var s = 
	"<div style='width:1046px;margin:0 auto;background:#eeeeee;height:50px;margin-top:20px;margin-bottom:20px;padding-left:20px;padding-top:20px;border:1px solid blue;'>"
	  +"<label class='form-inline' />站点:"
	  +"<input id='startaddress' class='form-control' type='text' style='width:200px' />"
	  +"<button class='btn' id='myfind'>查询</button>"
	  +"</label>"
	  +"</div>";
	
	//用于显示查询结果
	s += "<div id='showtable'></div>";
		
	var obj = document.getElementById("content");
	obj.innerHTML = s;
	
	//注册“查询”按钮消息
	g_addIdEvent("myfind", "click", g_appObj.findProc);
}

TrainStartFind.prototype.findProc = function(){
	var address = g_trim_id("startaddress");

	var data = "address="+address;
	xmlHttp.open("post","myfind_train", true);
	xmlHttp.onreadystatechange = g_appObj.findProc_Response;
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.send(data);												
}

TrainStartFind.prototype.findProc_Response = function(){
	if(xmlHttp.readyState == 4){
		if(xmlHttp.status == 200){
			var dataobj = g_parseJSONString(xmlHttp.responseText);
			//画表头
			var s = 
			    "<table border='1'>"
	        +"<tr style='background:#0087c8;color:white;'>"
			+"<th class='myth' style='width:150px;'>车次</th>"
			+"<th class='myth' style='width:150px;'>出发站<br>到达站</th>"
			+"<th class='myth' style='width:150px;'>出发时间<br>到达时间</th>"
			+"<th class='myth' style='width:150px;'>历时</th>"
			+"<th class='myth' style='width:150px;'>经停站点</th>"
			+"<th class='myth' style='width:150px;'>到站时刻</th>"
			+"</tr>";
			
			for(var i=0; i<dataobj.d.length; i++){
				if(i%2==0)
					 s += "<tr style='background:#eeeeee;color:black;'>";
				else
					 s += "<tr style='background:white;color:black;'>";
					
		          s += "<td class='myth'style='word-wrap:break-word;word-break:break-all;' width='200px';>"+dataobj.d[i].d2[0]+ "</td>"
		          +"<td class='myth'style='word-wrap:break-word;word-break:break-all;' width='200px';>"+dataobj.d[i].d2[1]+"<br>"+dataobj.d[i].d2[2]+"</td>"
		          +"<td class='myth'style='word-wrap:break-word;word-break:break-all;' width='200px';>"+dataobj.d[i].d2[3]+"<br>"+dataobj.d[i].d2[4]+"</td>"
		          +"<td class='myth'style='word-wrap:break-word;word-break:break-all;' width='200px';>"+dataobj.d[i].d2[5]+"分钟"+"<br>当日到达</td>"
		          +"<td class='myth'style='word-wrap:break-word;word-break:break-all;' width='200px';>"+dataobj.d[i].d2[6]+"</td>"
		          +"<td class='myth'style='word-wrap:break-word;word-break:break-all;' width='200px';>"+dataobj.d[i].d2[7]+"</td>"
		          +"</tr>"
			}
			s += "</table>";
			var obj = document.getElementById("showtable");
			obj.innerHTML = s;

		}
	}
	
}


function BusStartFind(){
	
}

BusStartFind.prototype.loadEngine = function(){
	var s = 
	"<div style='width:1046px;margin:0 auto;background:#eeeeee;height:50px;margin-top:20px;margin-bottom:20px;padding-left:20px;padding-top:20px;border:1px solid blue;'>"
	  +"<label class='form-inline' />站点:"
	  +"<input id='startaddress' class='form-control' type='text' style='width:200px' />"
	  +"<button class='btn' id='myfind'>查询</button>"
	  +"</label>"
	  +"</div>";
	
	//用于显示查询结果
	s += "<div id='showtable'></div>";
		
	var obj = document.getElementById("content");
	obj.innerHTML = s;
	
	//注册“查询”按钮消息
	g_addIdEvent("myfind", "click", g_appObj.findProc);
}

BusStartFind.prototype.findProc = function(){
	var address = g_trim_id("startaddress");

	var data = "address="+address;
	xmlHttp.open("post","myfind_bus", true);
	xmlHttp.onreadystatechange = g_appObj.findProc_Response;
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.send(data);												
}

BusStartFind.prototype.findProc_Response = function(){
	if(xmlHttp.readyState == 4){
		if(xmlHttp.status == 200){
			var dataobj = g_parseJSONString(xmlHttp.responseText);
			//画表头
			var s = 
			    "<table border='1'>"
	        +"<tr style='background:#0087c8;color:white;'>"
			+"<th class='myth' style='width:150px;'>车次</th>"
			+"<th class='myth' style='width:150px;'>出发站<br>到达站</th>"
			+"<th class='myth' style='width:150px;'>出发时间<br>到达时间</th>"
			+"<th class='myth' style='width:150px;'>历时</th>"
			+"<th class='myth' style='width:150px;'>距离</th>"
			+"<th class='myth' style='width:150px;'>经停站点</th>"
			+"<th class='myth' style='width:150px;'>到站时刻</th>"
			+"</tr>";
			
			for(var i=0; i<dataobj.d.length; i++){
				if(i%2==0)
					 s += "<tr style='background:#eeeeee;color:black;'>";
				else
					 s += "<tr style='background:white;color:black;'>";
					
		          s += "<td class='myth'>"+dataobj.d[i].d2[0]+ "</td>"
		          +"<td class='myth'>"+dataobj.d[i].d2[1]+"<br>"+dataobj.d[i].d2[2]+"</td>"
		          +"<td class='myth'>"+dataobj.d[i].d2[3]+"<br>"+dataobj.d[i].d2[4]+"</td>"
		          +"<td class='myth'>"+dataobj.d[i].d2[5]+"分钟"+"<br>当日到达</td>"
		          +"<td class='myth'>"+dataobj.d[i].d2[6]+"</td>"
		          +"<td class='myth'>"+dataobj.d[i].d2[7]+"</td>"
		          +"<td class='myth'>"+dataobj.d[i].d2[8]+"</td>"
		          +"</tr>"
			}
			s += "</table>";
			var obj = document.getElementById("showtable");
			obj.innerHTML = s;

		}
	}
	
}


function AirStartFind(){
	
}

AirStartFind.prototype.loadEngine = function(){
	var s = 
	"<div style='width:1046px;margin:0 auto;background:#eeeeee;height:50px;margin-top:20px;margin-bottom:20px;padding-left:20px;padding-top:20px;border:1px solid blue;'>"
	  +"<label class='form-inline' />站点:"
	  +"<input id='startaddress' class='form-control' type='text' style='width:200px' />"
	  +"<button class='btn' id='myfind'>查询</button>"
	  +"</label>"
	  +"</div>";
	
	//用于显示查询结果
	s += "<div id='showtable'></div>";
		
	var obj = document.getElementById("content");
	obj.innerHTML = s;
	
	//注册“查询”按钮消息
	g_addIdEvent("myfind", "click", g_appObj.findProc);
}

AirStartFind.prototype.findProc = function(){
	var address = g_trim_id("startaddress");

	var data = "address="+address;
	xmlHttp.open("post","myfind_air", true);
	xmlHttp.onreadystatechange = g_appObj.findProc_Response;
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.send(data);												
}

AirStartFind.prototype.findProc_Response = function(){
	if(xmlHttp.readyState == 4){
		if(xmlHttp.status == 200){
			var dataobj = g_parseJSONString(xmlHttp.responseText);
			//画表头
			var s = 
			    "<table border='1'>"
	        +"<tr style='background:#0087c8;color:white;'>"
			+"<th class='myth' style='width:150px;'>车次</th>"
			+"<th class='myth' style='width:150px;'>出发站<br>到达站</th>"
			+"<th class='myth' style='width:150px;'>出发时间<br>到达时间</th>"
			+"<th class='myth' style='width:150px;'>历时</th>"
			+"<th class='myth' style='width:150px;'>距离</th>"
			+"<th class='myth' style='width:150px;'>经停站点</th>"
			+"<th class='myth' style='width:150px;'>到站时刻</th>"
			+"</tr>";
			
			for(var i=0; i<dataobj.d.length; i++){
				if(i%2==0)
					 s += "<tr style='background:#eeeeee;color:black;'>";
				else
					 s += "<tr style='background:white;color:black;'>";
					console.log(dataobj)
					
		          s += "<td class='myth'>"+dataobj.d[i].d2[0]+ "</td>"
		          +"<td class='myth'style='word-wrap:break-word;word-break:break-all;'>"+dataobj.d[i].d2[1]+"<br>"+dataobj.d[i].d2[2]+"</td>"
		          +"<td class='myth'style='word-wrap:break-word;word-break:break-all;'>"+dataobj.d[i].d2[3]+"<br>"+dataobj.d[i].d2[4]+"</td>"
		          +"<td class='myth'style='word-wrap:break-word;word-break:break-all;'>"+dataobj.d[i].d2[5]+"分钟"+"</td>"
		          +"<td class='myth'style='word-wrap:break-word;word-break:break-all;'>"+dataobj.d[i].d2[6]+"</td>"
		          +"<td class='myth'style='word-wrap:break-word;word-break:break-all;'>"+dataobj.d[i].d2[7]+"</td>"
		          +"<td class='myth'>"+dataobj.d[i].d2[4]+"</td>"
		          +"</tr>"
			}
			s += "</table>";
			var obj = document.getElementById("showtable");
			obj.innerHTML = s;

		}
	}
	
}















//-------间隔查询代码------

function IntervalQuery(e){
	var obj = e.target || window.event.srcElement;
	switch(obj.getAttribute("key")){
	case "Intervaltrain":
		g_appObj = new TrainIntervalFind();
		break;	
	case "Intervalair":
		g_appObj = new AirIntervalFind();
		break;
	case "Intervalbus":
		g_appObj = new BusIntervalFind();
		break;
	}
	g_appObj.loadEngine();	
}

//-------TrainIntervalFind代码--------

function TrainIntervalFind(){
	
}

TrainIntervalFind.prototype.loadEngine=function(){
		var s = 
		"<div style='width:1046px;margin:0 auto;background:#eeeeee;height:50px;margin-top:20px;margin-bottom:20px;padding-left:20px;padding-top:20px;border:1px solid blue;'>"
		  +"<label class='form-inline' />"
		  +"出发站:<input id='startaddress' class='form-control' type='text' style='width:200px' />"
		  +"&nbsp"
		  +"目的站:<input id='endaddress' class='form-control' type='text' style='width:200px' />"
		  +"<button class='btn' id='intervalfind'>查询</button>"
		  +"</label>"
		  +"</div>";
		
		//用于显示查询结果
		s += "<div id='showtable'></div>";
			
		var obj = document.getElementById("content");
		obj.innerHTML = s;
		
		//注册“查询”按钮消息
		g_addIdEvent("intervalfind", "click", g_appObj.findProc);
	
}

TrainIntervalFind.prototype.findProc = function(){
	var startaddress = g_trim_id("startaddress");
	var endaddress=g_trim_id("endaddress");
	var data = "addresses="+startaddress+","+endaddress;
	xmlHttp.open("post", "intervalfind_train", true);
	xmlHttp.onreadystatechange = g_appObj.findProc_Response;
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.send(data);												
}

TrainIntervalFind.prototype.findProc_Response = function(){
	if(xmlHttp.readyState == 4){
		if(xmlHttp.status == 200){
			var dataobj = g_parseJSONString(xmlHttp.responseText);
			//画表头
			var s="";
			if(dataobj.d[0].d2[0]=="transit"){
				s += 
			    "<table border='1'>"
	        +"<tr style='background:#0087c8;color:white;'>"
			+"<th class='myth' style='width:100px;'>车次</th>"
			+"<th class='myth' style='width:80px;'>出发站</th>"
			+"<th class='myth' style='width:150px;'>经停站点<br>(前段)</th>"
			+"<th class='myth' style='width:150px;'>站点时刻</th>"
			+"<th class='myth' style='width:80px;'>中转站点</th>"
			+"<th class='myth' style='width:150px;'>经停站点<br>(后段)</th>"
			+"<th class='myth' style='width:150px;'>站点时刻</th>"
			+"<th class='myth' style='width:80px;'>终点站</th>"
			+"<th class='myth' style='width:100px;'>历时</th>"
			+"</tr>";
			}
			else if(dataobj.d[0].d2[0]=="transitdouble"){
				s += 
				    "<table border='1'>"
		        +"<tr style='background:#0087c8;color:white;'>"
				+"<th class='myth' style='width:200px;'>车次</th>"
				+"<th class='myth' style='width:200px;'>出发站</th>"
				+"<th class='myth' style='width:200px;'>经停站点(前段)<br>站点时刻(前段)</th>"
				+"<th class='myth' style='width:200px;'>经停站点(中间)<br>站点时刻(中间)</th>"
				+"<th class='myth' style='width:200px;'>经停站点(后段)<br>站点时刻(后段)</th>"
				+"<th class='myth' style='width:200px;'>终点站</th>"
				+"<th class='myth' style='width:200px;'>历时</th>"
				+"</tr>";
				
			}
			else if(dataobj.d[0].d2[0]=="straight"){
				s += 
				    "<table border='1'>"
		        +"<tr style='background:#0087c8;color:white;'>"
				+"<th class='myth' style='width:200px;'>车次</th>"
				+"<th class='myth' style='width:200px;'>出发站<br>到达站</th>"
				+"<th class='myth' style='width:200px;'>出发时间<br>到达时间</th>"
				+"<th class='myth' style='width:200px;'>历时</th>"
				+"<th class='myth' style='width:200px;'>经停站点</th>"
				+"<th class='myth' style='width:200px;'>站点时刻</th>"
				+"</tr>";
			}
			for(var i=0; i<dataobj.d.length; i++){
				if(i%2==0)
					 s += "<tr style='background:#eeeeee;color:black;'>";
				else
					 s += "<tr style='background:white;color:black;'>";
					if(dataobj.d[i].d2[0]=="transit"){
		          s += "<td class='myth'>"+dataobj.d[i].d2[1]+ "</td>"
		          +"<td class='myth'style='word-wrap:break-word;word-break:break-all;'>"+dataobj.d[i].d2[2]+"</td>"
		          +"<td class='myth'style='word-wrap:break-word;word-break:break-all;'>"+dataobj.d[i].d2[3]+"</td>"
		          +"<td class='myth'style='word-wrap:break-word;word-break:break-all;'>"+dataobj.d[i].d2[4]+"</td>"
		          +"<td class='myth'style='word-wrap:break-word;word-break:break-all;'>"+dataobj.d[i].d2[5]+"</td>"
		          +"<td class='myth'style='word-wrap:break-word;word-break:break-all;'>"+dataobj.d[i].d2[6]+"</td>"
		          +"<td class='myth'style='word-wrap:break-word;word-break:break-all;'>"+dataobj.d[i].d2[7]+"</td>"
		          +"<td class='myth'style='word-wrap:break-word;word-break:break-all;'>"+dataobj.d[i].d2[8]+"</td>"
		          +"<td class='myth'style='word-wrap:break-word;word-break:break-all;'>"+dataobj.d[i].d2[9]+"</td>"
		          +"</tr>"	
		          }
				else if(dataobj.d[i].d2[0]=="transitdouble"){
				          s += "<td class='myth'style='word-wrap:break-word;word-break:break-all;'>"+dataobj.d[i].d2[1]+ "</td>"
				          +"<td class='myth'style='word-wrap:break-word;word-break:break-all;'>"+dataobj.d[i].d2[2]+"</td>" 
				          +"<td class='myth'style='word-wrap:break-word;word-break:break-all;'>"+dataobj.d[i].d2[3]+"<br>"+dataobj.d[i].d2[4]+"</td>"
				          +"<td class='myth'style='word-wrap:break-word;word-break:break-all;'>"+dataobj.d[i].d2[5]+"<br>"+dataobj.d[i].d2[6]+"</td>"
				          +"<td class='myth'style='word-wrap:break-word;word-break:break-all;'>"+dataobj.d[i].d2[7]+"<br>"+dataobj.d[i].d2[8]+"</td>"
				          +"<td class='myth'style='word-wrap:break-word;word-break:break-all;'>"+dataobj.d[i].d2[9]+"</td>"
				          +"<td class='myth'style='word-wrap:break-word;word-break:break-all;'>"+dataobj.d[i].d2[10]+"</td>"
				          +"</tr>"	
					}
					else if(dataobj.d[i].d2[0]=="straight"){
				 s += "<td class='myth'>"+dataobj.d[i].d2[1]+ "</td>"
				 +"<td class='myth'style='word-wrap:break-word;word-break:break-all;'>"+dataobj.d[i].d2[2]+"<br>"+dataobj.d[i].d2[3]+"</td>"
				 +"<td class='myth'style='word-wrap:break-word;word-break:break-all;'>"+dataobj.d[i].d2[4]+"<br>"+dataobj.d[i].d2[5]+"</td>"
				 +"<td class='myth'style='word-wrap:break-word;word-break:break-all;'>"+dataobj.d[i].d2[6]+"</td>"
				 +"<td class='myth'style='word-wrap:break-word;word-break:break-all;'>"+dataobj.d[i].d2[7]+"</td>"
				 +"<td class='myth'style='word-wrap:break-word;word-break:break-all;'>"+dataobj.d[i].d2[8]+"</td>"
				 +"</tr>"
				}
			}
			s += "</table>";
			var obj = document.getElementById("showtable");
			obj.innerHTML = s;

		}
	}
	
}


function BusIntervalFind(){
	
}

BusIntervalFind.prototype.loadEngine=function(){
		var s = 
		"<div style='width:1046px;margin:0 auto;background:#eeeeee;height:50px;margin-top:20px;margin-bottom:20px;padding-left:20px;padding-top:20px;border:1px solid blue;'>"
		  +"<label class='form-inline' />"
		  +"出发站:<input id='startaddress' class='form-control' type='text' style='width:200px' />"
		  +"&nbsp"
		  +"目的站:<input id='endaddress' class='form-control' type='text' style='width:200px' />"
		  +"<button class='btn' id='intervalfind'>查询</button>"
		  +"</label>"
		  +"</div>";
		
		//用于显示查询结果
		s += "<div id='showtable'></div>";
			
		var obj = document.getElementById("content");
		obj.innerHTML = s;
		
		//注册“查询”按钮消息
		g_addIdEvent("intervalfind", "click", g_appObj.findProc);
	
}

BusIntervalFind.prototype.findProc = function(){
	var startaddress = g_trim_id("startaddress");
	var endaddress=g_trim_id("endaddress");
	var data = "addresses="+startaddress+","+endaddress;
	xmlHttp.open("post", "intervalfind_bus", true);
	xmlHttp.onreadystatechange = g_appObj.findProc_Response;
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.send(data);												
}

BusIntervalFind.prototype.findProc_Response = function(){
	if(xmlHttp.readyState == 4){
		if(xmlHttp.status == 200){
			var dataobj = g_parseJSONString(xmlHttp.responseText);
			//画表头
			var s="";
			if(dataobj.d[0].d2[0]=="transit"){
				s += 
			    "<table border='1'>"
	        +"<tr style='background:#0087c8;color:white;'>"
			+"<th class='myth' style='width:100px;'>车次</th>"
			+"<th class='myth' style='width:80px;'>出发站</th>"
			+"<th class='myth' style='width:150px;'>经停站点<br>(前段)</th>"
			+"<th class='myth' style='width:100px;'>站点时刻</th>"
			+"<th class='myth' style='width:80px;'>中转站点</th>"
			+"<th class='myth' style='width:150px;'>经停站点<br>(后段)</th>"
			+"<th class='myth' style='width:150px;'>站点时刻</th>"
			+"<th class='myth' style='width:80px;'>终点站</th>"
			+"<th class='myth' style='width:80px;'>历时</th>"
			+"</tr>";
			}
			else if(dataobj.d[0].d2[0]=="straight"){
				s += 
				    "<table border='1'>"
		        +"<tr style='background:#0087c8;color:white;'>"
				+"<th class='myth' style='width:200px;'>车次</th>"
				+"<th class='myth' style='width:200px;'>出发站<br>到达站</th>"
				+"<th class='myth' style='width:200px;'>出发时间<br>到达时间</th>"
				+"<th class='myth' style='width:200px;'>历时</th>"
				+"<th class='myth' style='width:200px;'>经停站点</th>"
				+"<th class='myth' style='width:200px;'>站点时刻</th>"
				+"</tr>";
			}
			for(var i=0; i<dataobj.d.length; i++){
				if(i%2==0)
					 s += "<tr style='background:#eeeeee;color:black;'>";
				else
					 s += "<tr style='background:white;color:black;'>";
					if(dataobj.d[i].d2[0]=="transit"){
		          s += "<td class='myth'>"+dataobj.d[i].d2[1]+ "</td>"
		          +"<td class='myth'>"+dataobj.d[i].d2[2]+"</td>"
		          +"<td class='myth'>"+dataobj.d[i].d2[3]+"</td>"
		          +"<td class='myth'>"+dataobj.d[i].d2[4]+"</td>"
		          +"<td class='myth'>"+dataobj.d[i].d2[5]+"</td>"
		          +"<td class='myth'>"+dataobj.d[i].d2[6]+"</td>"
		          +"<td class='myth'>"+dataobj.d[i].d2[7]+"</td>"
		          +"<td class='myth'>"+dataobj.d[i].d2[8]+"</td>"
		          +"<td class='myth'>"+dataobj.d[i].d2[9]+"</td>"
		          +"</tr>"	
		          }
					else if(dataobj.d[i].d2[0]=="straight"){
				 s += "<td class='myth'>"+dataobj.d[i].d2[1]+ "</td>"
				 +"<td class='myth'>"+dataobj.d[i].d2[2]+"<br>"+dataobj.d[i].d2[3]+"</td>"
				 +"<td class='myth'>"+dataobj.d[i].d2[4]+"<br>"+dataobj.d[i].d2[5]+"</td>"
				 +"<td class='myth'>"+dataobj.d[i].d2[6]+"</td>"
				 +"<td class='myth'>"+dataobj.d[i].d2[7]+"</td>"
				 +"<td class='myth'>"+dataobj.d[i].d2[8]+"</td>"
				 +"</tr>"
				}
			}
			s += "</table>";
			var obj = document.getElementById("showtable");
			obj.innerHTML = s;

		}
	}
	
}


function AirIntervalFind(){
	
}

AirIntervalFind.prototype.loadEngine=function(){
		var s = 
		"<div style='width:1046px;margin:0 auto;background:#eeeeee;height:50px;margin-top:20px;margin-bottom:20px;padding-left:20px;padding-top:20px;border:1px solid blue;'>"
		  +"<label class='form-inline' />"
		  +"出发站:<input id='startaddress' class='form-control' type='text' style='width:200px' />"
		  +"&nbsp"
		  +"目的站:<input id='endaddress' class='form-control' type='text' style='width:200px' />"
		  +"<button class='btn' id='intervalfind'>查询</button>"
		  +"</label>"
		  +"</div>";
		
		//用于显示查询结果
		s += "<div id='showtable'></div>";
			
		var obj = document.getElementById("content");
		obj.innerHTML = s;
		
		//注册“查询”按钮消息
		g_addIdEvent("intervalfind", "click", g_appObj.findProc);
	
}

AirIntervalFind.prototype.findProc = function(){
	var startaddress = g_trim_id("startaddress");
	var endaddress=g_trim_id("endaddress");
	var data = "addresses="+startaddress+","+endaddress;
	xmlHttp.open("post", "intervalfind_air", true);
	xmlHttp.onreadystatechange = g_appObj.findProc_Response;
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.send(data);												
}

AirIntervalFind.prototype.findProc_Response = function(){
	if(xmlHttp.readyState == 4){
		if(xmlHttp.status == 200){
			var dataobj = g_parseJSONString(xmlHttp.responseText);
			//画表头
			var s="";
			if(dataobj.d[0].d2[0]=="transit"){
				s += 
			    "<table border='1'>"
	        +"<tr style='background:#0087c8;color:white;'>"
			+"<th class='myth' style='width:100px;'>车次</th>"
			+"<th class='myth' style='width:80px;'>出发站</th>"
			+"<th class='myth' style='width:150px;'>经停站点<br>(前段)</th>"
			+"<th class='myth' style='width:100px;'>站点时刻</th>"
			+"<th class='myth' style='width:80px;'>中转站点</th>"
			+"<th class='myth' style='width:150px;'>经停站点<br>(后段)</th>"
			+"<th class='myth' style='width:150px;'>站点时刻</th>"
			+"<th class='myth' style='width:80px;'>终点站</th>"
			+"<th class='myth' style='width:80px;'>历时</th>"
			+"</tr>";
			}
			else if(dataobj.d[0].d2[0]=="straight"){
				s += 
				    "<table border='1'>"
		        +"<tr style='background:#0087c8;color:white;'>"
				+"<th class='myth' style='width:200px;'>车次</th>"
				+"<th class='myth' style='width:200px;'>出发站<br>到达站</th>"
				+"<th class='myth' style='width:200px;'>出发时间<br>到达时间</th>"
				+"<th class='myth' style='width:200px;'>历时</th>"
				+"<th class='myth' style='width:200px;'>经停站点</th>"
				+"<th class='myth' style='width:200px;'>站点时刻</th>"
				+"</tr>";
			}
			for(var i=0; i<dataobj.d.length; i++){
				if(i%2==0)
					 s += "<tr style='background:#eeeeee;color:black;'>";
				else
					 s += "<tr style='background:white;color:black;'>";
					if(dataobj.d[i].d2[0]=="transit"){
		          s += "<td class='myth'>"+dataobj.d[i].d2[1]+ "</td>"
		          +"<td class='myth'>"+dataobj.d[i].d2[2]+"</td>"
		          +"<td class='myth'>"+dataobj.d[i].d2[3]+"</td>"
		          +"<td class='myth'>"+dataobj.d[i].d2[4]+"</td>"
		          +"<td class='myth'>"+dataobj.d[i].d2[5]+"</td>"
		          +"<td class='myth'>"+dataobj.d[i].d2[6]+"</td>"
		          +"<td class='myth'>"+dataobj.d[i].d2[7]+"</td>"
		          +"<td class='myth'>"+dataobj.d[i].d2[8]+"</td>"
		          +"<td class='myth'>"+dataobj.d[i].d2[9]+"</td>"
		          +"</tr>"	
		          }
					else if(dataobj.d[i].d2[0]=="straight"){
				 s += "<td class='myth'>"+dataobj.d[i].d2[1]+ "</td>"
				 +"<td class='myth'>"+dataobj.d[i].d2[2]+"<br>"+dataobj.d[i].d2[3]+"</td>"
				 +"<td class='myth'>"+dataobj.d[i].d2[4]+"<br>"+dataobj.d[i].d2[5]+"</td>"
				 +"<td class='myth'>"+dataobj.d[i].d2[6]+"</td>"
				 +"<td class='myth'>"+dataobj.d[i].d2[7]+"</td>"
				 +"<td class='myth'>"+dataobj.d[i].d2[8]+"</td>"
				 +"</tr>"
				}
			}
			s += "</table>";
			var obj = document.getElementById("showtable");
			obj.innerHTML = s;

		}
	}
	
}




function WiseQuery(e){
	var obj = e.target || window.event.srcElement;
	switch(obj.getAttribute("key")){
	case "Wisetrain":
		g_appObj = new TrainWiseFind();
		break;	
	case "Wiseair":
		g_appObj = new AirWiseFind();
		break;
	}
	g_appObj.loadEngine();	
}

function TrainWiseFind(){
	
}

TrainWiseFind.prototype.loadEngine=function(){
		var s = 
		"<div style='width:1046px;margin:0 auto;background:#eeeeee;height:50px;margin-top:20px;margin-bottom:20px;padding-left:20px;padding-top:20px;border:1px solid blue;'>"
		  +"<label class='form-inline' />"
		  +"出发站:<input id='startaddress' class='form-control' type='text' style='width:200px' />"
		  +"&nbsp"
		  +"目的站:<input id='endaddress' class='form-control' type='text' style='width:200px' />"
		  +"<button class='btn' id='wisefind'>查询</button>"
		  +"</label>"
		  +"</div>";
		
		//用于显示查询结果
		s += "<div id='showtable'></div>";
			
		var obj = document.getElementById("content");
		obj.innerHTML = s;
		
		//注册“查询”按钮消息
		g_addIdEvent("wisefind", "click", g_appObj.findProc);
	
}

TrainWiseFind.prototype.findProc = function(){
	var startaddress = g_trim_id("startaddress");
	var endaddress=g_trim_id("endaddress");
	var data = "addresses="+startaddress+","+endaddress;
	xmlHttp.open("post", "wisefind", true);
	xmlHttp.onreadystatechange = g_appObj.findProc_Response;
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.send(data);												
}

TrainWiseFind.prototype.findProc_Response=function(){
	if(xmlHttp.readyState == 4){
		if(xmlHttp.status == 200){
			var dataobj = g_parseJSONString(xmlHttp.responseText);
			//画表头
			var s = 
			    "<table border='1'>"
	        +"<tr style='background:#0087c8;color:white;'>"
	        +"<th class='myth' style='width:90px;'>方案</th>"
			+"<th class='myth' style='width:90px;'>车次</th>"
			+"<th class='myth' style='width:100px;'>出发站<br>到达站</th>"
			+"<th class='myth' style='width:82px;'>出发时间<br>到达时间</th>"
			+"<th class='myth' style='width:82px;'>路线总时长</th>"
			+"<th class='myth' style='width:66px;'>距离</th>"
			+"<th class='myth' style='width:150px;'>历经站点</th>"
			+"<th class='myth' style='width:150px;'>起始站点</th>"
			+"<th class='myth' style='width:80px;'>目标站点</th>"
			+"<th class='myth' style='width:80px;'>本次行程所需时间</th>"
			+"</tr>";
			var flag;
			for(var i=0; i<dataobj.d.length; i++){
				if(i==0) flag=dataobj.d[i].d2[10];
				if(i%2==0)
					 s += "<tr style='background:#eeeeee;color:black;'>";
				else
					 s += "<tr style='background:white;color:black;'>";
				var value=dataobj.d[i].d2[10].split(",");
				var time=value[0];
				var day=value[1];
				if(dataobj.d[i].d2[10]==flag){
						s +="<td class='myth'>"+"最优方案"+ "</td>"
						+"<td class='myth'>"+dataobj.d[i].d2[0]+ "</td>"
						+"<td class='myth'>"+dataobj.d[i].d2[1]+"<br>"+dataobj.d[i].d2[2]+"</td>"
						+"<td class='myth'>"+dataobj.d[i].d2[3]+"<br>"+dataobj.d[i].d2[4]+"</td>"
						+"<td class='myth'>"+dataobj.d[i].d2[5]+"分钟"+"<br>"+day+"</td>"
						+"<td class='myth'>"+dataobj.d[i].d2[6]+"</td>"
						+"<td class='myth'>"+dataobj.d[i].d2[7]+"</td>"
						+"<td class='myth'>"+dataobj.d[i].d2[8]+"</td>"
						+"<td class='myth'>"+dataobj.d[i].d2[9]+"</td>"
						+"<td class='myth'>"+time+"</td>"
						+"</tr>"	
		          }	
				else{
						s +="<td class='myth'>"+"较好方案"+ "</td>"
			          +"<td class='myth'>"+dataobj.d[i].d2[0]+ "</td>"
			          +"<td class='myth'>"+dataobj.d[i].d2[1]+"<br>"+dataobj.d[i].d2[2]+"</td>"
			          +"<td class='myth'>"+dataobj.d[i].d2[3]+"<br>"+dataobj.d[i].d2[4]+"</td>"
			          +"<td class='myth'>"+dataobj.d[i].d2[5]+"分钟"+"<br>"+day+"</td>"
			          +"<td class='myth'>"+dataobj.d[i].d2[6]+"</td>"
			          +"<td class='myth'>"+dataobj.d[i].d2[7]+"</td>"
			          +"<td class='myth'>"+dataobj.d[i].d2[8]+"</td>"
			          +"<td class='myth'>"+dataobj.d[i].d2[9]+"</td>"
			          +"<td class='myth'>"+time+"</td>"
			          +"</tr>"
					}
				}
					

			}
			s += "</table>";
			var obj = document.getElementById("showtable");
			obj.innerHTML = s;
			
				
		}
	}









